const gulp = require('gulp')
const sass = require('gulp-sass')(require('sass'))
const rename = require('gulp-rename')
const inject = require('gulp-inject-string')

function defaultTask(cb) {
    sassBuild()
    cb()
}

function sassBuild() {
    return gulp.src(['**/*.scss','!node_modules/**/*.scss','!style/*.scss'])
        .pipe(inject.prepend('@import \'./style/root.scss\';'))
        .pipe(sass().on('error', sass.logError))
        .pipe(rename(path=>{path.extname = '.wxss'})) // 修改导出文件后缀名
        .pipe(gulp.dest('.'))
}

gulp.watch(['**/*.scss','!node_modules/**/*.scss','!style/*.scss'], sassBuild)

exports.sass = sassBuild
exports.default = defaultTask